
<%@ include file="/common/taglibs.jsp"%>
<!--分页查询共用的页面-->
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript" src="<%=jsPath%>/jquery/jquery.timers.js"></script><!--定时器-->
<script type="text/javascript" src="<%=jsPath%>/terminalCommand.js"></script><!--终端命令结果查询-->

<script>
	/*
	修改代码：
	1.新定义变量TerminalCommmand，为命令支持变量
	2.重定义id：
	原：null		现：doorControlCommandMsg
	原：null		现：doorControlBtn
	原：		现：
	*/

	var tc2DoorControl = new TerminalCommand2();
     var timerName = "doorControlTimer";
	///////////////////////////////////////////////////////////////
$().ready(function() {
	tc2DoorControl.messageDiv = $("#doorControlCommandMsg");
	tc2DoorControl.timerName = timerName;
	tc2DoorControl.commandButton = $("#doorControlBtn");
	 $("#doorControlEntityForm").validate(); //初始化验证信息
	 
	 Utility.ajaxSubmitForm("doorControlEntityForm", {
						 success:function(responseText)
						 {
							   var result = responseText;
								if (result.success) {
									 var commandId = result.data; //下发成功后，获取到命令Id
									 tc2DoorControl.startQueryResult(commandId,null,onCommandSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
									 
								}
								else {
									$("#doorControlCommandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
									//停止所有的在$('body')上定时器  
									$('body').stopTime (timerName);  
								  }
						 }
	 });
});


//下发车门指令后，对终端点名，要下最新位置信息
function callTerminal()
{
	var url = '<%=ApplicationPath%>/terminalCall/send.action';
	var params = {vehicleId:'${vehicleId}'};
	$.getJSON(url, params, function(result)
	{
		if (result.success) {									
			var commandId = result.data; //下发成功后，获取到命令Id
			tc2DoorControl.times=100;
			tc2DoorControl.startQueryResult(commandId,null,onCallTerminalCommandSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
		}

	});
}


function onCallTerminalCommandSuccess(result)
{		
    //停止所有的在$('body')上定时器  
	$('body').stopTime (timerName);  
	$("#doorControlCommandMsg").html("命令执行结果:"+result.message);
	if(result.message && result.message == "命令执行成功")
	{
						 //alert(result.message);
		var vehicleId = "${vehicleId}";
		parent.MyMap.showVehicleOnMap(vehicleId);
		//parent.closeCommandWindow();
	}
}
//查询命令执行结果
var myMap = parent.myMap;
function onCommandSuccess(result)
{		
					 //停止所有的在$('body')上定时器  
	$('body').stopTime (timerName);  
	$("#doorControlCommandMsg").html("命令执行结果:"+result.message);
	if(result.message && result.message == "命令执行成功")
	{
		//callTerminal();//呼叫点名
		var vehicleId = "${vehicleId}";
		parent.MyMap.showVehicleOnMap(vehicleId);
	}
}


</script>
 <BODY>
	<form id="doorControlEntityForm" name="doorControlEntityForm" 
			action='<%=ApplicationPath%>/doorControl/send.action' method="POST">
				
        <input type="hidden"  name="controlType"  id="controlType" value="0"/>
        <input type="hidden"  name="vehicleId"  id="vehicleId" value="${vehicleId}"/>
  <table width="100%"  class="TableBlock">
					<tbody><tr>
						<td colspan="2" style="font-weight: bold; background: #EFEFEF;" height="25">车门控制
						<span style="color:red;background:blue;">${message}</span>
						</td>
					</tr>
					<tr>
						<td align="right">控制类型
							:</td>
						<td><select id="switchState"  style="width: 150px;" name="switchState" class="required digits">
						<option value="0">车门解锁</option>
						<option value="1">车门加锁</option>
						   </select></td>
					</tr>
				<tr>
						<td colspan=2 align="center">
						   <input id="doorControlBtn" type="submit" class="sendjson" value="发送">
						   <span id="doorControlCommandMsg" class="commandMsg"></span></td>
					</tr>

				
					
				</tbody></table>
 </BODY>
</HTML>
